package com.jeesite.modules.yl.web;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.yl.entity.YlWorker;
import com.jeesite.modules.yl.service.YlWorkerService;

/**
 * 工人信息表Controller
 * @author ccz
 * @version 2025-03-24
 */
@Controller
@RequestMapping(value = "${adminPath}/yl/ylWorker")
public class YlWorkerController extends BaseController {

	@Autowired
	private YlWorkerService ylWorkerService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public YlWorker get(String id, boolean isNewRecord) {
		return ylWorkerService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("yl:ylWorker:view")
	@RequestMapping(value = {"list", ""})
	public String list(YlWorker ylWorker, Model model) {
		model.addAttribute("ylWorker", ylWorker);
		return "modules/yl/ylWorkerList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("yl:ylWorker:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<YlWorker> listData(YlWorker ylWorker, HttpServletRequest request, HttpServletResponse response) {
		ylWorker.setPage(new Page<>(request, response));
		Page<YlWorker> page = ylWorkerService.findPage(ylWorker);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("yl:ylWorker:view")
	@RequestMapping(value = "form")
	public String form(YlWorker ylWorker, Model model) {
		model.addAttribute("ylWorker", ylWorker);
		return "modules/yl/ylWorkerForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("yl:ylWorker:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated YlWorker ylWorker) {
		ylWorkerService.save(ylWorker);
		return renderResult(Global.TRUE, text("保存工人信息表成功！"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("yl:ylWorker:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(YlWorker ylWorker) {
		ylWorkerService.delete(ylWorker);
		return renderResult(Global.TRUE, text("删除工人信息表成功！"));
	}

	/**
	 * 查询删除删除数据
	 */
	@RequiresPermissions("yl:ylWorker:edit")
	@RequestMapping(value = "deleteList")
	@ResponseBody
	public String deleteList(List<String> list) {
		System.out.println(list.toString());
		String s =  ylWorkerService.deleteList(list);
		return "删除成功";
	}

	/**
	 * 修改状态
	 */
	@RequiresPermissions("yl:ylWorker:edit")
	@RequestMapping(value = "updateStatus")
	@ResponseBody
	public String updateStatus(@RequestBody List<String> list) {
		String s = ylWorkerService.updateYlStatus(list);
		return s;
	}
	
}